﻿using System.Reflection;
using static Worldme.YHChatSDK.Framework.Vo.PluginManagerVo;
using Worldme.YHChatSDK.Framework.EventInterface;
using Worldme.YHChatSDK.Framework.Vo;

namespace Worldme.YHChatSDK.Framework.Core
{
    internal class PluginLoadHandler
    {
        public static List<PluginManagerVo.EventMessageReceiveNormalVo> LoadEventMessageReceiveNormal()
        {
            List<PluginManagerVo.EventMessageReceiveNormalVo> list = new List<PluginManagerVo.EventMessageReceiveNormalVo>();
            Assembly currentAssembly = Assembly.GetEntryAssembly();

            foreach (Type type in currentAssembly.GetTypes())
            {
                if (typeof(EventMessageReceiveNormal).IsAssignableFrom(type) && !type.IsInterface)
                {
                    EventMessageReceiveNormal plugin = (EventMessageReceiveNormal)Activator.CreateInstance(type);
                    EventMessageReceiveNormalVo eventVo = new EventMessageReceiveNormalVo();
                    eventVo.Order = plugin.Order;
                    eventVo.Bean = plugin;
                    eventVo.PluginName = type.Name;
                    list.Add(eventVo);
                }
            }
            list = list.OrderBy(p => p.Order).ToList();
            return list;
        }

        public static List<PluginManagerVo.EventMessageReceiveInstructionVo> LoadEventMessageReceiveInstruction()
        {
            List<PluginManagerVo.EventMessageReceiveInstructionVo> list = new List<PluginManagerVo.EventMessageReceiveInstructionVo>();
            Assembly currentAssembly = Assembly.GetEntryAssembly();

            foreach (Type type in currentAssembly.GetTypes())
            {
                if (typeof(EventMessageReceiveInstruction).IsAssignableFrom(type) && !type.IsInterface)
                {
                    EventMessageReceiveInstruction plugin = (EventMessageReceiveInstruction)Activator.CreateInstance(type);
                    EventMessageReceiveInstructionVo eventVo = new EventMessageReceiveInstructionVo();
                    eventVo.Order = plugin.Order;
                    eventVo.Bean = plugin;
                    eventVo.PluginName = type.Name;
                    list.Add(eventVo);
                }
            }
            list = list.OrderBy(p => p.Order).ToList();
            return list;
        }


        public static List<PluginManagerVo.EventBotFollowedVo> LoadEventBotFollowed()
        {
            List<PluginManagerVo.EventBotFollowedVo> list = new List<PluginManagerVo.EventBotFollowedVo>();
            Assembly currentAssembly = Assembly.GetEntryAssembly();

            foreach (Type type in currentAssembly.GetTypes())
            {
                if (typeof(EventBotFollowed).IsAssignableFrom(type) && !type.IsInterface)
                {
                    EventBotFollowed plugin = (EventBotFollowed)Activator.CreateInstance(type);
                    EventBotFollowedVo eventVo = new EventBotFollowedVo();
                    eventVo.Order = plugin.Order;
                    eventVo.Bean = plugin;
                    eventVo.PluginName = type.Name;
                    list.Add(eventVo);
                }
            }
            list = list.OrderBy(p => p.Order).ToList();
            return list;
        }

        public static List<PluginManagerVo.EventBotUnfollowedVo> LoadEventBotUnfollowed()
        {
            List<PluginManagerVo.EventBotUnfollowedVo> list = new List<PluginManagerVo.EventBotUnfollowedVo>();
            Assembly currentAssembly = Assembly.GetEntryAssembly();

            foreach (Type type in currentAssembly.GetTypes())
            {
                if (typeof(EventBotUnfollowed).IsAssignableFrom(type) && !type.IsInterface)
                {
                    EventBotUnfollowed plugin = (EventBotUnfollowed)Activator.CreateInstance(type);
                    EventBotUnfollowedVo eventVo = new EventBotUnfollowedVo();
                    eventVo.Order = plugin.Order;
                    eventVo.Bean = plugin;
                    eventVo.PluginName = type.Name;
                    list.Add(eventVo);
                }
            }
            list = list.OrderBy(p => p.Order).ToList();
            return list;
        }

        public static List<PluginManagerVo.EventButtonReportInlineVo> LoadEventButtonReportInline()
        {
            List<PluginManagerVo.EventButtonReportInlineVo> list = new List<PluginManagerVo.EventButtonReportInlineVo>();
            Assembly currentAssembly = Assembly.GetEntryAssembly();

            foreach (Type type in currentAssembly.GetTypes())
            {
                if (typeof(EventButtonReportInline).IsAssignableFrom(type) && !type.IsInterface)
                {
                    EventButtonReportInline plugin = (EventButtonReportInline)Activator.CreateInstance(type);
                    EventButtonReportInlineVo eventVo = new EventButtonReportInlineVo();
                    eventVo.Order = plugin.Order;
                    eventVo.Bean = plugin;
                    eventVo.PluginName = type.Name;
                    list.Add(eventVo);
                }
            }
            list = list.OrderBy(p => p.Order).ToList();
            return list;
        }

        public static List<PluginManagerVo.EventGroupJoinVo> LoadEventGroupJoin()
        {
            List<PluginManagerVo.EventGroupJoinVo> list = new List<PluginManagerVo.EventGroupJoinVo>();
            Assembly currentAssembly = Assembly.GetEntryAssembly();

            foreach (Type type in currentAssembly.GetTypes())
            {
                if (typeof(EventGroupJoin).IsAssignableFrom(type) && !type.IsInterface)
                {
                    EventGroupJoin plugin = (EventGroupJoin)Activator.CreateInstance(type);
                    EventGroupJoinVo eventVo = new EventGroupJoinVo();
                    eventVo.Order = plugin.Order;
                    eventVo.Bean = plugin;
                    eventVo.PluginName = type.Name;
                    list.Add(eventVo);
                }
            }
            list = list.OrderBy(p => p.Order).ToList();
            return list;
        }

        public static List<PluginManagerVo.EventGroupLeaveVo> LoadEventGroupLeave()
        {
            List<PluginManagerVo.EventGroupLeaveVo> list = new List<PluginManagerVo.EventGroupLeaveVo>();
            Assembly currentAssembly = Assembly.GetEntryAssembly();

            foreach (Type type in currentAssembly.GetTypes())
            {
                if (typeof(EventGroupLeave).IsAssignableFrom(type) && !type.IsInterface)
                {
                    EventGroupLeave plugin = (EventGroupLeave)Activator.CreateInstance(type);
                    EventGroupLeaveVo eventVo = new EventGroupLeaveVo();
                    eventVo.Order = plugin.Order;
                    eventVo.Bean = plugin;
                    eventVo.PluginName = type.Name;
                    list.Add(eventVo);
                }
            }
            list = list.OrderBy(p => p.Order).ToList();
            return list;
        }

        public static List<PluginManagerVo.EventBotShutcutMenuVo> LoadEventBotShutcutMenu()
        {
            List<PluginManagerVo.EventBotShutcutMenuVo> list = new List<PluginManagerVo.EventBotShutcutMenuVo>();
            Assembly currentAssembly = Assembly.GetEntryAssembly();

            foreach (Type type in currentAssembly.GetTypes())
            {
                if (typeof(EventBotShutcurMenu).IsAssignableFrom(type) && !type.IsInterface)
                {
                    EventBotShutcurMenu plugin = (EventBotShutcurMenu)Activator.CreateInstance(type);
                    EventBotShutcutMenuVo eventVo = new EventBotShutcutMenuVo();
                    eventVo.Order = plugin.Order;
                    eventVo.Bean = plugin;
                    eventVo.PluginName = type.Name;
                    list.Add(eventVo);
                }
            }
            list = list.OrderBy(p => p.Order).ToList();
            return list;
        }
    }
}
